import { Component, OnInit, Input, TemplateRef } from '@angular/core';
// import ngx-bootstrap
import { BsModalService }   from 'ngx-bootstrap/modal';
import { BsModalRef }       from 'ngx-bootstrap/modal/modal-options.class';
import { Subscription }     from 'rxjs/Subscription';
import { Observable }       from 'rxjs/Observable';
import { ExpressionDialog } from './expression-dialog/expression-dialog.component';
import { cbCfgList }        from './../condition/condition-builder.config';

@Component({
  selector: 'app-expression',
  templateUrl: './expression.html',
  styleUrls: ['./expression.css']
})
export class ExpressionComponent {

  @Input('condition') expressions: any[];

  value1: any;
  value2: any;


  public modalRef: BsModalRef;
  constructor(
    private modalService: BsModalService
  ) { }

  public openModal() {
    this.modalRef                             = this.modalService.show(ExpressionDialog);
    this.modalRef.content.title               = "Show Condition";
    this.modalRef.content.conditionDetailList = this.values;
    this.modalRef.content.expressionDetail    = this.expressions;
    (<ExpressionDialog>this.modalRef.content).showExpressionModal(this.expressions);
  }

  public values                 = new Array();
  public expressionDialogValues = new Array();

  ngOnInit() {
    for (let i = 0; i < this.expressions.length; i++) {
      if ( this.expressions[i].id == 1) {
          var exp = "rank " + this.expressions[i].operation + " " + this.expressions[i].value;
          this.values.push(exp);
      }
      else if ( this.expressions[i].id == 2) {
        var exp = "rating " + this.expressions[i].operation + " " + this.expressions[i].value;
        this.values.push(exp);
      }
      else if ( this.expressions[i].id == 3) {
        var exp = "review " + this.expressions[i].operation + " " + this.expressions[i].value;
        this.values.push(exp);
      }
      else if ( this.expressions[i].id == 4) {
        var exp = "price " + this.expressions[i].operation + " " + this.expressions[i].value;
        this.values.push(exp);
      }
      else if ( this.expressions[i].id == 5) {
        var exp = "listing disable";
        this.values.push(exp);
      }
    }
  }
}
